#include <bits/stdc++.h>

using namespace std;

struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution
{
public:
    void recursion(TreeNode *root)
    {
        if (root == nullptr)
        {
            return;
        }
        recursion(root->left);
        if (pre != nullptr && root->val - pre->val < min_diff)
        {
            min_diff = root->val - pre->val;
        }
        pre = root;
        recursion(root->right);
        return;
    }
    int getMinimumDifference(TreeNode *root)
    {
        recursion(root);
        return min_diff;
    }
    TreeNode *pre = nullptr;
    int min_diff = INT_MAX;
};

int main()
{
    TreeNode *root = new TreeNode(4);
    root->left = new TreeNode(2);
    root->right = new TreeNode(6);
    root->left->left = new TreeNode(1);
    root->left->right = new TreeNode(3);
    Solution sol;
    cout << sol.getMinimumDifference(root) << endl;
    return 0;
}